package ru.isys.yoomee.ui;

import ru.isys.yoomee.R;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

@SuppressWarnings("deprecation")
public class YooMeeTabActivity extends TabActivity {
	Resources mResources;
	

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.yoomee_tab_layout);
		mResources = getResources();		
		initializeTabs();
	}

	private void initializeTabs() {

		TabHost tabHost = getTabHost();
		TabHost.TabSpec spec;
		Intent intent;

		intent = new Intent(this, TimemapActivity.class);
		spec = tabHost.newTabSpec("timemap_tab").setIndicator(prepareTabIcon(0)).setContent(intent);
		tabHost.addTab(spec);
		
		intent = new Intent(this, VenuesTabActivity.class);
		spec = tabHost.newTabSpec("venues_tab").setIndicator(prepareTabIcon(1)).setContent(intent);
		tabHost.addTab(spec);

		intent = new Intent(this, YoosTabActivity.class);
		spec = tabHost.newTabSpec("yoos_tab").setIndicator(prepareTabIcon(2)).setContent(intent);
		tabHost.addTab(spec);
		
		intent = new Intent(this, ChatsTabActivity.class);
		spec = tabHost.newTabSpec("chats_tab").setIndicator(prepareTabIcon(3)).setContent(intent);
		tabHost.addTab(spec);

		tabHost.setCurrentTab(0);

	}

	private View prepareTabIcon(int index) {

		View tab= getLayoutInflater().inflate(R.layout.yoomee_tab, null);
		switch (index) {
		case 0: {
			((ImageView) tab.findViewById(R.id.tab_icon)).setImageDrawable(mResources
					.getDrawable(R.drawable.timemap_tab_btn));
			((TextView) tab.findViewById(R.id.tab_text)).setText(R.string.timemap_tab);
			break;
		}
		case 1: {
			((ImageView) tab.findViewById(R.id.tab_icon)).setImageDrawable(mResources
					.getDrawable(R.drawable.venues_tab_btn));
			((TextView) tab.findViewById(R.id.tab_text)).setText(R.string.venues_tab);
			break;
		}
		case 2: {
			((ImageView) tab.findViewById(R.id.tab_icon)).setImageDrawable(mResources
					.getDrawable(R.drawable.yoos_tab_btn));
			((TextView) tab.findViewById(R.id.tab_text)).setText(R.string.yoos_tab);
			break;
		}
		case 3: {
			((ImageView) tab.findViewById(R.id.tab_icon)).setImageDrawable(mResources
					.getDrawable(R.drawable.chats_tab_btn));
			((TextView) tab.findViewById(R.id.tab_text)).setText(R.string.chats_tab);
			break;
		}
		}
		return tab;

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.yoomee_menu_layout, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
		case R.id.mee_config:
			startMeeConfigActivity();
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	private void startMeeConfigActivity() {
		startActivity(new Intent(this, MeeActivity.class));
	}

}
